package com.miracle.java2110.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;

import java.util.Arrays;

/**
 * TODO
 *
 * @Author: Wang
 * @Date: 2021/11/13 21:16
 */
public class serviceConverter implements Converter<String[]> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return String.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    /**
     * 这里读的时候会调用
     *
     * @param context
     * @return
     */
    @Override
    public String[] convertToJavaData(ReadConverterContext<?> context) {
        String stringValue = context.getReadCellData().getStringValue();
        return stringValue.split(",");
    }

    /**
     * 这里是写的时候会调用 不用管
     *
     * @return
     * @param context
     */
    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<String[]> context) {
        return new WriteCellData<String[]>(Arrays.toString(context.getValue()));
    }

}
